package com.innovations.inn.service.impl;

import java.util.List;
import com.innovations.common.utils.DateUtils;
import com.innovations.common.utils.uuid.IdGeneratorSnowflake;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.innovations.inn.mapper.CooperationIntentionMapper;
import com.innovations.inn.domain.CooperationIntention;
import com.innovations.inn.service.ICooperationIntentionService;

/**
 * 合作意向Service业务层处理
 * 
 * @author dp
 * @date 2024-08-09
 */
@Service
public class CooperationIntentionServiceImpl implements ICooperationIntentionService 
{
    @Autowired
    private CooperationIntentionMapper cooperationIntentionMapper;
    @Autowired
    IdGeneratorSnowflake idGeneratorSnowflake;

    /**
     * 查询合作意向
     * 
     * @param cooperationIntentionId 合作意向主键
     * @return 合作意向
     */
    @Override
    public CooperationIntention selectCooperationIntentionByCooperationIntentionId(Long cooperationIntentionId)
    {
        return cooperationIntentionMapper.selectCooperationIntentionByCooperationIntentionId(cooperationIntentionId);
    }

    /**
     * 查询合作意向列表
     * 
     * @param cooperationIntention 合作意向
     * @return 合作意向
     */
    @Override
    public List<CooperationIntention> selectCooperationIntentionList(CooperationIntention cooperationIntention)
    {
        return cooperationIntentionMapper.selectCooperationIntentionList(cooperationIntention);
    }

    /**
     * 新增合作意向
     * 
     * @param cooperationIntention 合作意向
     * @return 结果
     */
    @Override
    public int insertCooperationIntention(CooperationIntention cooperationIntention)
    {
        cooperationIntention.setCreateTime(DateUtils.getNowDate());
        return cooperationIntentionMapper.insertCooperationIntention(cooperationIntention);
    }

    /**
     * 修改合作意向
     * 
     * @param cooperationIntention 合作意向
     * @return 结果
     */
    @Override
    public int updateCooperationIntention(CooperationIntention cooperationIntention)
    {
        return cooperationIntentionMapper.updateCooperationIntention(cooperationIntention);
    }

    /**
     * 批量删除合作意向
     * 
     * @param cooperationIntentionIds 需要删除的合作意向主键
     * @return 结果
     */
    @Override
    public int deleteCooperationIntentionByCooperationIntentionIds(Long[] cooperationIntentionIds)
    {
        return cooperationIntentionMapper.deleteCooperationIntentionByCooperationIntentionIds(cooperationIntentionIds);
    }

    /**
     * 删除合作意向信息
     * 
     * @param cooperationIntentionId 合作意向主键
     * @return 结果
     */
    @Override
    public int deleteCooperationIntentionByCooperationIntentionId(Long cooperationIntentionId)
    {
        return cooperationIntentionMapper.deleteCooperationIntentionByCooperationIntentionId(cooperationIntentionId);
    }

    /**
     * 实体数据补全
     *
     * @param cooperationIntention 实体
     * @param userId       用户id
     * @param crateType    创建类型 1：新增 2：修改
     */
    @Override
    public void completeData(CooperationIntention cooperationIntention, Long userId, Integer crateType) {
        //主键
        if (cooperationIntention.getCooperationIntentionId() == null || "".equals(cooperationIntention.getCooperationIntentionId())) {
            cooperationIntention.setCooperationIntentionId(idGeneratorSnowflake.nextId());
        }
        //创建人、创建时间
        if (crateType == 1) {
            if (cooperationIntention.getCreateBy() == null || "".equals(cooperationIntention.getCreateBy())) {
                cooperationIntention.setCreateBy(userId);
            }
            if (cooperationIntention.getCreateTime() == null) {
                cooperationIntention.setCreateTime(DateUtils.getNowDate());
            }
        }
        //修改人
        if (cooperationIntention.getModifyBy() == null) {
            cooperationIntention.setModifyBy(userId);
        }
        //修改时间
        if (cooperationIntention.getModifyTime() == null) {
            cooperationIntention.setModifyTime(DateUtils.getNowDate());
        }
    }
}
